import 'package:flutter/material.dart';
import 'package:kasax/utils/log_utils.dart';

class AnimHomeWidget3 extends StatefulWidget {
  const AnimHomeWidget3({Key? key}) : super(key: key);

  @override
  _AnimHomeWidget3State createState() => _AnimHomeWidget3State();
}

class _AnimHomeWidget3State extends State<AnimHomeWidget3> with SingleTickerProviderStateMixin {
  late AnimationController _animationController;

  @override
  void initState() {
    super.initState();

    /// value 动画的值 ，默认是lowerBound
    _animationController =
        AnimationController(value: 32, lowerBound: 32, upperBound: 220, vsync: this, duration: Duration(seconds: 3));
    _animationController.addListener(() {
      setState(() {});
    });
    _animationController.addStatusListener((status) {
      LogUtil.e("$status");
      switch (status) {
        case AnimationStatus.forward:
          LogUtil.e("动画开始执行了");
          break;
        case AnimationStatus.completed:
          LogUtil.e("动画执行完成了");
          break;
        case AnimationStatus.dismissed:
          LogUtil.e("动画取消了");
          break;
        case AnimationStatus.reverse:
          LogUtil.e("动画反转");
          break;
      }
    });
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: IconButton(
          onPressed: () {
            switch (_animationController.status) {
              case AnimationStatus.completed:
                // 反转执行动画
                _animationController.reverse();
                break;
              default:
                // 执行动画
                _animationController.forward();
                break;
            }
          },
          iconSize: _animationController.value,
          icon: Icon(Icons.star),
          color: Colors.deepOrange,
        ),
      ),
    );
  }
}
